﻿using System;
using System.Windows.Forms;
using Ast.Core.Services;
using Ast.Framework.Forms;
using Ast.Framework.Services;

namespace Ast.Keyboard
{
    [FormMetadata("Keyboard")]
    public partial class KeyboardForm : Form
    {
        private readonly IClock _clock;
        private readonly IKeyboardService _keyboardService;

        public KeyboardForm(IClock clock, IKeyboardService keyboardService)
        {
            _clock = clock;
            _keyboardService = keyboardService;

            InitializeComponent();
        }

        private async void btnType_Click(object sender, EventArgs e)
        {
            txbInput.Text += string.Format("{0}\r\n", _clock.UtcNow.ToLongTimeString());
            txbInput.SelectionStart = txbInput.Text.Length;
            txbInput.Focus();

            await _keyboardService.PressKey(Keys.A);
            await _keyboardService.PressKey(Keys.B);
            await _keyboardService.PressKey(Keys.C);
            await _keyboardService.PressKey(Keys.D);
            await _keyboardService.PressKey(Keys.E);
            await _keyboardService.PressKey(Keys.F);
            await _keyboardService.PressKey(Keys.G);
            await _keyboardService.PressKey(Keys.Back);
            await _keyboardService.PressKey(Keys.Enter);
        }
    }
}